 package com.suozq.current;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 锁战强
 * @date 2022/04/12
 */
 public class AtomicBooleanTest implements Runnable{
     public static AtomicBoolean exits = new AtomicBoolean(true);
    
     @Override
     public synchronized void run() {
         System.out.println("begin run");
         System.out.println("real " + exits.get());
         if(exits.compareAndSet(true,false)){
             System.out.println(Thread.currentThread().getName() + "  " + exits.get() );
             exits.set(true);
         }else{
             run();
         }
     }
     
     public static void main(String[] args) {
         AtomicBooleanTest abd = new AtomicBooleanTest();
         Thread t1 = new Thread(abd);
         Thread t2 = new Thread(abd);
         t1.start();
         t2.start();
         ReentrantLock rl = new ReentrantLock();     
         rl.lock();
     }

 }